import java.lang.reflect.Constructor;

public class demo5 {

    public demo5() throws ClassNotFoundException {
        Class clz = Class.forName("Person");
        try {
            Constructor c1 = clz.getDeclaredConstructor();
            Object obj = c1.newInstance();
            System.out.println(obj);
            //获取Person
            Constructor c2 = clz.getDeclaredConstructor(String.class);
            c2.setAccessible(true);
            obj = c2.newInstance("New Person");
            System.out.println(obj);
            //获取Person三参数构造
            Constructor c3 = clz.getDeclaredConstructor(String.class, String.class, String.class);
            c3.setAccessible(true);
            obj = c3.newInstance("New Person", "beijing", "Hello");
            System.out.println(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
